<template>
  <div class="table-page-search-wrapper">
    <el-form :model="form" ref="form" :inline="true" label-width="100px">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="党支部名称" prop="branchId">
            <dept-select ref="branchSelect" @select="e => handleDeptSelect(e, 'branch')" />
            <!-- <el-input v-model="form.branchId" placeholder="输入党支部名称搜索" /> -->
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="科室">
            <dept-select ref="deptSelect" @select="e => handleDeptSelect(e, 'dept')" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-tooltip class="item" content="查询" effect="dark" placement="top">
            <el-button type="primary" @click="handleSearch" icon="el-icon-search" />
          </el-tooltip>
          <el-tooltip class="item" content="重置" effect="dark" placement="top">
            <el-button @click="handleReset" icon="el-icon-refresh-right" />
          </el-tooltip>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import DeptSelect from '@/components/DeptSelect'
export default {
  components: {
    DeptSelect
  },
  data() {
    return {
      form: {}
    }
  },
  methods: {
    handleDeptSelect(e, type) {
      if (type === 'branch') {
        this.$set(this.form, 'branchId', e.id)
      } else {
        this.$set(this.form, 'deptId', e.id)
      }
      console.log('form', this.form)
    },
    handleSearch() {
      this.$emit('search', this.form)
    },
    handleReset() {
      this.$refs.branchSelect.reset()
      this.$refs.deptSelect.reset()
      this.$set(this.form, 'deptId', null)
      // this.$refs.form.resetFields()
      this.$emit('search', this.form)
    }
  }
}
</script>

<style scoped>
.el-form-item {
  margin-bottom: 10px;
}
</style>